import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { DeptQuery, DeptPageResult, DeptForm } from './types';

/**
 * 获取主管单位分页数据
 *
 * @param queryParams
 */
export function getDeptPage(
  queryParams?: DeptQuery
): AxiosPromise<DeptPageResult> {
  return request({
    url: '/api/v1/depts/page',
    method: 'get',
    params: queryParams
  });
}




/**
 * 获取主管单位详情
 *
 * @param id
 */
export function getDeptForm(id: number): AxiosPromise<DeptForm> {
  return request({
    url: '/api/v1/depts/' + id + '/form',
    method: 'get'
  });
}

/**
 * 添加主管单位
 *
 * @param data
 */
export function addDept(data: DeptForm) {
  return request({
    url: '/api/v1/depts/create',
    method: 'post',
    data: data
  });
}

/**
 * 更新主管单位
 *
 * @param id
 * @param data
 */
export function updateDept(id: number, data: DeptForm) {
  return request({
    url: '/api/v1/depts/' + id,
    method: 'put',
    data: data
  });
}

/**
 * 批量删除主管单位，多个以英文逗号(,)分割
 *
 * @param ids
 */
export function deleteDepts(ids: string) {
  return request({
    url: '/api/v1/depts/' + ids,
    method: 'delete'
  });
}

/**
 * 
 * @returns 获取部门下拉
 */
export function  listDeptOptions(){
  return request({
    url: '/api/v1/depts/options',
    method: 'get',
  });  
}